<?php
namespace app\admin\controller;
use think\Db;
use app\admin\model\Admin as AdminModel;
use app\admin\controller\Common;

class Pass extends Common
{
    public function index()
    {
    	$admin = Db::name('admin')->where('username',session('username'))->find();
		$this->assign('admin',$admin);
        return view();
    }

    public function edit($id)
    {
    	$admin = Db::name('admin')->where('id',$id)->find();
    	if(!$admin){
    		$this->error('该管理员不存在');
    	}else{
    		if(request()->ispost()){
    			$editadmin = new AdminModel();
                $res = $editadmin->editadmin($_POST,$admin);
                if($res == 1) {
                    $this->success('修改成功');
                }else if($res == 2){
                    $this->error('修改失败');
                }else if($res == 3){
                    $this->error('密码错误');
                }
    		}else{
    			$this->error('修改失败');
    		}
    	}
    }
}
